Skip to content

Make busybox securityContext configurable#649

Draft
janhoy wants to merge 1 commit intoapache:mainfrom
janhoy:busybox-init-securityContext
Draft

Make busybox securityContext configurable#649
janhoy wants to merge 1 commit intoapache:mainfrom
janhoy:busybox-init-securityContext

Conversation

@janhoy
Copy link
Contributor

@janhoy janhoy commented Oct 27, 2023

Draft PR, only code, not docs, no helm support.

The busybox official image runs as root in cp-solr-xml init-container, and there is no way to configure it otherwise, other than point to a different image that has been manipulated as non-root.

By adding a SecurityContext for the init container defaulting to the nobody user and setting runAsNonRoot: true, we have a good default. By also making the securityContext configurable, we allow for people to switch to a different image with other UID etc. Example:

spec:
  busyBoxImage:
    tag: 1.36.1-glibc
  busyBoxSecurityContext:
    runAsUser: 123

Fixes #582

@janhoy janhoy requested a review from HoustonPutman October 27, 2023 19:03
@janhoy janhoy marked this pull request as draft October 27, 2023 19:04
@janhoy janhoy changed the title WIP: Make busybox securityContext configurable Make busybox securityContext configurable Oct 27, 2023
@janhoy
Copy link
Contributor Author

janhoy commented Oct 28, 2023

Alternatively, should perhaps the spec for cp-solr-xml init container be configurable as one yaml dict instead of two? Still defaults in code, but end users could perhaps override more properties of the container in a more familiar and transparent way. Example:

spec:
  cpSolrXmlInitContainer:
    image:
      registry: public.ecr.aws
      repository: my-company/busybox
      tag: 1.37.0-custom
      imagePullSecret: foo
    securityContext:
      runAsUser: 1000
      runAsGroup: 1000

PS: By splitting image into registy, repository and tag, it is easier for downstream users to customize just the registry part.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a configurable securityContext for the cp-solr-xml BusyBox init container so SolrCloud pods can be run with runAsNonRoot: true, while also updating the BusyBox default tag used by the operator/chart.

Changes:

  • Add busyBoxSecurityContext to the SolrCloud API (type + defaults) and propagate it into the generated cp-solr-xml init container.
  • Update SolrCloud CRD schemas to expose busyBoxSecurityContext (both config/ and Helm CRD bundles).
  • Update the documented BusyBox image tag in the Helm chart values.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
helm/solr/values.yaml Updates the commented BusyBox tag to 1.36.1-glibc.
helm/solr-operator/crds/crds.yaml CRD schema update to include busyBoxSecurityContext.
config/crd/bases/solr.apache.org_solrclouds.yaml Base CRD schema update to include busyBoxSecurityContext.
api/v1beta1/common_types.go Adds ContainerSecurityContext helper type and conversion to corev1.SecurityContext.
api/v1beta1/solrcloud_types.go Adds busyBoxSecurityContext field + defaulting (UID/GID 65534, non-root).
api/v1beta1/zz_generated.deepcopy.go Generated deepcopy support for the new type/field.
controllers/util/solr_util.go Applies the new securityContext to the cp-solr-xml init container.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 754 to 761
Command: []string{"sh", "-c", strings.Join(setupCommands, " && ")},
VolumeMounts: volumeMounts,
Resources: corev1.ResourceRequirements{
Requests: volumePrepResources,
Limits: volumePrepResources,
},
SecurityContext: solrCloud.Spec.BusyBoxSecurityContext.ToSC(),
}
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting a non-root SecurityContext on the cp-solr-xml init container can break the existing backup-repository prep logic in this same container: when BackupRepositories include volume mounts, setupCommands may include addgroup/adduser/su and chown, which typically require root (or extra capabilities) and will fail when running as UID/GID 65534. Consider either (a) skipping/reworking the user-creation + chown path when BusyBoxSecurityContext enforces non-root (e.g., rely on FSGroup and only do a write-test with a clear error), or (b) splitting the permission-fixup into a separate, optionally-root init container so cp-solr-xml can remain non-root for runAsNonRoot: true pods.

Copilot uses AI. Check for mistakes.
Comment on lines +213 to +217
if spec.BusyBoxSecurityContext == nil {
c := ContainerSecurityContext{}
spec.BusyBoxSecurityContext = &c
}
changed = spec.BusyBoxSecurityContext.withDefaults(DefaultBusyBoxUserId, DefaultBusyBoxGroupId, DefaultBusyBoxRunAsNonRoot) || changed
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New defaulting for BusyBoxSecurityContext introduces user-visible behavior (init container securityContext defaults to UID/GID 65534 and runAsNonRoot: true), but there doesn’t appear to be controller/unit test coverage asserting the generated StatefulSet’s cp-solr-xml init container gets this securityContext (and that overrides work). Adding assertions in the existing controller tests that inspect init containers would help prevent regressions, especially given the interaction with PodSecurityContext/FSGroup and backup-repo prep.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Run init container cp-solr-xml as nonRoot

2 participants